/*
 *  tfwriter.cpp
 *  Perceel
 *
 *  Created by Nicola Gigante on 24/04/08.
 *  Copyright 2008 Nicola Gigante. All rights reserved.
 *
 */

#include "tfwriter.h"

bool TFWriter::write(QList<TF> list)
{
	setAutoFormatting(true);
	
	writeStartDocument();
	writeStartElement("perceel");
	writeAttribute("version", "0.1");
	
	foreach(TF tf, list)
	{
		writeStartElement("function");
		writeStartElement("roots");
	
		QList<Complex> roots = tf.roots();
		foreach(Complex r, roots)
		{
			writeEmptyElement("root");
			writeAttribute("real", QString::number(real(r)));
			writeAttribute("imag", QString::number(imag(r)));
		}
		writeEndElement(); // </roots>
		
		writeStartElement("poles");
		
		QList<Complex> poles = tf.poles();
		foreach(Complex p, poles)
		{
			writeEmptyElement("pole");
			writeAttribute("real", QString::number(real(p)));
			writeAttribute("imag", QString::number(imag(p)));
		}
		writeEndElement(); // </roots>
		
		writeEndElement(); // </function>
	}
	
	writeEndElement(); // </perceel>
	writeEndDocument();
	
	return true;
}
